package edu.umn.msse.farside.FourH.web;

import edu.umn.msse.farside.FourH.domain.Event;
import org.apache.commons.lang.StringUtils;
import org.springframework.validation.BindingResult;

public class EventValidator
{
    public EventValidator()
    {
    }

    public void validate(Event event, BindingResult result)
    {
        // any validation checking
        if (StringUtils.isBlank(event.getName()))
        {
            result.rejectValue("name", "required", "Required");  // property resource
        }

        if (StringUtils.isBlank(event.getDescription()))
        {
            result.rejectValue("description", "required", "Required");
        }

        if (null == event.getStartDateAndTime())
        {
            result.rejectValue("startDateAndTime", "required", "Required");
        }

        if (null == event.getEndDateAndTime())
        {
            result.rejectValue("endDateAndTime", "required", "Required");
        }

        if ((null != event.getStartDateAndTime()) && (null != event.getEndDateAndTime()))
        {
            if (!event.getStartDateAndTime().before(event.getEndDateAndTime()))
            {
                result.rejectValue("endDateAndTime", "invalid", "Must be after start date");
            }
        }
    }
}